import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Role } from './role.entity';
import { Menu } from './menu.entity';

@Entity('role_menus')
export class RoleMenu {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: number;

  @Column({ type: 'bigint', comment: '角色ID' })
  roleId: number;

  @Column({ type: 'bigint', comment: '菜单ID' })
  menuId: number;

  @CreateDateColumn({ comment: '创建时间' })
  createTime: Date;

  @ManyToOne(() => Role, role => role.roleMenus, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'role_id' })
  role: Role;

  @ManyToOne(() => Menu, menu => menu.roleMenus, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'menu_id' })
  menu: Menu;
}